﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace ConfigInfoWebPlatform.API.BusinessCommon
{
    public static class CommonHandle
    {
        /// <summary>
        /// 将XML字符串反序列化为对象
        /// </summary>
        /// <typeparam name="T">对象类型</typeparam>
        /// <param name="xml">XML字符</param>
        /// <returns></returns>
        public static T DeserializeToObject<T>(string xml)
        {
            T myObject;
            XmlSerializer serializer = new XmlSerializer(typeof(T));
            StringReader reader = new StringReader(xml);
            myObject = (T)serializer.Deserialize(reader);
            reader.Close();
            return myObject;
        }
        /// <summary>
        /// 数组切片操作
        /// </summary>
        /// <param name="srcArr">源数组</param>
        /// <param name="startIndex">从源数组的哪个位置开始切</param>
        /// <param name="len">切片长度</param>
        /// <param name="connectChar">数组元素之间通过哪种字符拼接成字符串</param>
        /// <returns></returns>
        public static string Arra_cut(string[] srcArr, int startIndex, int len, string connectChar)
        {
            string[] temparr = new string[len];
            Array.Copy(srcArr, startIndex, temparr, 0, len);
            string tempstr = string.Join(connectChar, temparr);
            return tempstr;
        }

    }
}
